package com.vehicle.controller;
import com.vehicle.form.ContactForm;
import com.vehicle.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-04-20
 */
@RestController
@RequestMapping("/contact")
public class ContactController {

    @Autowired
    ContactService contactService;

    //添加联系人
    @PostMapping("/add")
    public Integer addContact(@RequestBody ContactForm contactForm){
        return contactService.insertContact(contactForm);
    }


    //获取联系人
    @GetMapping("/getMessage/{contactId}")
    public ContactForm getContactMessage(@PathVariable("contactId") Integer contactId) {
        return contactService.getContactById(contactId);
    }

    //修改联系人
    @PutMapping("/")
    public Boolean updateContact(@ModelAttribute ContactForm contactForm){
        return contactService.updateTheContact(contactForm);
    }

    //删除联系人
    @DeleteMapping("/deleteById/{contactId}")
    public Boolean deleteContact(@PathVariable("contactId") Integer contactId) {
        return contactService.deleteContactById(contactId);
    }

}

